<%-- 
    Document   : update1
    Created on : 2014/8/19, 下午 04:43:24
    Author     : gjun
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String id = request.getParameter("id");
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/javadb", "root", "root");
    Statement st=con.createStatement();
    String sql="select id , username , tel ,birthday from person where id=" + id ;
    System.out.println(sql);
 
    
  %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>hello world</h1>
     <%
        ResultSet rs= st.executeQuery(sql);
        if( rs.next()){
            
            String username  = rs.getString("username");
            String tel  = rs.getString("tel");
            String birthday  = rs.getString("birthday");
             %>
            
        <form action="update2.jsp">
            username:<input type="text" name="username" value="<%= username %>"><br>
            tel:<input type="text" name="tel" value="<%= tel %>"><br>
            birthday:<input type="text" name="birthday" value="<%= birthday %>"><br>
            <input type="hidden" name="id" value="<%= id %>"><!--隱藏欄位-->
            <input type="submit" >
        </form>
                        
            <%
            //out.println(id+"," + username +"," +tel +","+birthday+"<br>");
        }else{
            out.println("查無資料");
        }
        rs.close();
        st.close();
        con.close();
    %>
    </body>
</html>


